package simulation;

import java.util.List;
import util.Location;


public abstract class CenterOfMass extends Force {
	private double myMagnitude;
	private static final String DEFAULT_NAME = "Center of mass";
	
	
	
	public CenterOfMass(double magnitude){
		super(DEFAULT_NAME);
		myMagnitude=magnitude;
		
	}
	public double getMagnitude(){
		return myMagnitude;
	}
	
	public Location calculateCenter(List<Mass> Masses){
		double totalMass=0;
		double sumX=0;
		double sumY=0;
		for (Mass m:Masses){
			sumX+=m.getMass()*m.getX();
			sumY+=m.getMass()*m.getY();
			totalMass+=m.getMass();
		}
		double centerX=sumX/totalMass;
		double centerY=sumY/totalMass;
				
		return new Location(centerX,centerY);
		
	}
	
	@Override
	public abstract void apply(List<Mass> myMasses);
}
